// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: jshin

#pragma once

#include <map>
#include <memory>
#include <regex>
#include <string>
#include <vector>

// internal
#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"

namespace coin2::exchange::gdax::feed_v1 {
namespace impl {
using namespace coin2::exchange::base::symbology;
class GdaxFeedProcessor : public base::feed::FeedParsingProcessor {
 public:
  explicit GdaxFeedProcessor(
      const std::string& system_name,
      const coin2::exchange::di::ConstantInjection& ci,
      const feed::RawParserConfig& config)
      : FeedParsingProcessor(
            system_name,
            MarketExchangeApi{MarketType::Spot, ExchangeType::Gdax, "v1"},
            ci,
            config,
            "cc/coin2/exchange/gdax/feed_v1/schema.json"),
        publish_bbo_book_only_(config.publish_bbo_book_only()) {}
  void OnTopicRecord(const base::executor::TopicRecordPacket& packet) override;

 protected:
  const bool publish_bbo_book_only_;
};
struct GdaxChannel {
  std::string type;

  static GdaxChannel Parse(const std::string& type) {
    /*
    "match"
    "snapshot"
    "l2update"
    "subscriptions"
    */
    if (type == "match") {
      return GdaxChannel{"matches"};
    } else if (type == "snapshot" || type == "l2update") {
      return GdaxChannel{"level2"};
    } else if (
        type == "subscriptions" || type == "last_match" || type == "status" ||
        type == "ticker" || type == "error") {
      return GdaxChannel{"ignore"};
    } else {
      THROW() << "unknown channel: " << type;
      return GdaxChannel{};
    }
  }
};
};  // namespace impl
using impl::GdaxChannel;
using impl::GdaxFeedProcessor;
}  // namespace coin2::exchange::gdax::feed_v1
